using System;
using System.Data;
using System.Data.SqlClient;


namespace IBuyAdventure
{
   public class ProductsDB 
   {
      string m_ConnectionString;
      public ProductsDB( string dsn ) {
         m_ConnectionString = dsn;
      }

      public DataSet GetProduct(string productCode) {

          SqlConnection sqlConnection = new SqlConnection(m_ConnectionString);
          SqlDataAdapter sqlAdapter1 = new SqlDataAdapter("SELECT * FROM Products WHERE ProductCode='"+productCode+"'", sqlConnection);

          DataSet products = new DataSet();
          sqlAdapter1.Fill(products, "products");

          return products;
      }   
   
      public DataSet GetProducts(string category) {

          SqlConnection sqlConnection = new SqlConnection(m_ConnectionString);
          SqlDataAdapter sqlAdapter1 = new SqlDataAdapter("SELECT * FROM Products WHERE ProductType='"+category+"'", sqlConnection);

          DataSet products = new DataSet();
          sqlAdapter1.Fill(products, "products");

          return products;
      }

      public DataSet GetProductCategories() {

          SqlConnection sqlConnection = new SqlConnection(m_ConnectionString);
          SqlDataAdapter sqlAdapter1 = new SqlDataAdapter("SELECT Distinct ProductType FROM Products", sqlConnection);

          DataSet products = new DataSet();
          sqlAdapter1.Fill(products, "products");

          return products;
      }      
   }
}
